#include "ScubaSoldier.h"
#include "Box.h"
#include "RSManager.h"
#include "Sprite.h"
#include "Grenade.h"
#include "ShareComponents.h"
#include "Camera.h"
#include "ScubaSoldierBullet.h"
#include "MainGame.h"

ScubaSoldier::ScubaSoldier(Box* box) : Object(box, ObjEnemy_STATIC)
{
	_sprite = RSManager::getInstance()->getSprite(SCUBA_SOLDIER);
	delay = 0;	
	_box->_size = _sprite->getRenderSize();
	_isAlive = true;
	_hits = 1;
	_posBullet.x = _box->_position.x + 20;
	_posBullet.y = _box->_position.y + 40;		
	_colBox->_position = _box->_position;
	_colBox->_size = _box->_size;
	_colBox->_v= _box->_v;
}

ScubaSoldier::~ScubaSoldier(void)
{
}

void ScubaSoldier::update()
{
	if(gl_player->_position.y > _box->_position.y)
	{
		if(_hits <= 0)
			_isAlive = false;
		delay += GAME_TIME;
		if(delay >= 3000)
		{
			delay = 0 ;
			if(_sprite->GetCurrentIndex() == 1)
			{
				shoot();				
				_sprite->Next();
			}	
			else
			{
				delay = 2500;
				_sprite->Next();
			}
		}
	}
}

void ScubaSoldier::render()
{
	_sprite->Render(_box->_position);	
}

void ScubaSoldier::shoot()
{
	_up = new ScubaSoldierBullet(new Box(_posBullet, D3DXVECTOR2(0, 0), D3DXVECTOR2(3, 3)), 0, gl_camera->getBottom());
	gl_MainGame->addWorldObject(_up);
}

Box* ScubaSoldier::getCollisionBox()
{
	if(_sprite->GetCurrentIndex() == 0)	
		return gl_BOX_0_0_0;
	return _colBox;
}
